# -*- coding: utf-8 -*-..,
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp import netsvc



# 
class crea8s_fastech_estimate(osv.osv):
    _name = "crea8s.fastech.estimate"
    _description = 'crea8s_fastech_estimate asdasdasd.....sad.'
    _columns = {
        'fast_name': fields.char('Fast Name', size=256),
         'name': fields.char('Name', size=50),
        'customer': fields.many2one('res.partner', 'Customer'),
        'customer_ref': fields.char('Customer Reference', size=50),
        'date': fields.datetime('Date...+Time'),
        'amount_untaxed': fields.float('Untaxed Amount',digits=(3,2)),
        'amount_taxes': fields.float('Taxes', digits=(3,2)),
        'amount_total': fields.float('Total', digits=(3,2)),
        'note': fields.text('Terms and conditions'), 
#         'state': fields.char('State', size=50),
        'state' : fields.selection([('draft', 'Draft'), ('confirmed', 'Confirmed'), ('canceled', 'Canceled')], 'State'),
        'details': fields.one2many('crea8s.fastech.estimate.detail', 'crea8s_fastech_estimate_parent_id', 'Details'), 
        
        'estimate_no': fields.char('Estimate No', size=64), 
        'address': fields.char('Address', size=128), # +read only ; +from partner
        
        #??? is_company === TRUE 
        'vehicle_no': fields.char ('Vehicle No', size=128), 
        'make_model': fields.char ('Make/Model', size=128), #
        'chassis_eng': fields.char('Chassis / English', size=128), #
        
        'accident_date': fields.date('Accident Date'), # read only ; state not in DRAFT.
        'claim_no': fields.char('Claim No', size=64), #
        'policy_no': fields.char('Policy No', size=64), #
        
        'company_id': fields.many2one('res.company', 'Company', required=False),
        'currency_id': fields.related('company_id', 'currency_id', type="many2one", relation="res.currency", string="Currency", readonly=True),
        
# 'state': fields.selection([('draft','Draft'),
# ('confirmed','Confirmed')],'State',required=True,readonly=True)
    }
    
    _defaults = {
        'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crea8s.fastech.estimate', context=c),
        
    }
        
#     strFormatTime = '%Y-%m-%d %H:%M:%S %Z'
    def act_helloword(self, cr, uid, ids, context={}):
       return self.write(cr, uid, ids, {'name': 'Hello word (by crea8s_fastech_estimate)'})
   
    def button_dummy(self, cr, uid, ids, context={}):
        return 1
   
    def btn_send_email(self, cr, uid, ids, context={}):
        wf_service = netsvc.LocalService("workflow")
#         wf_service.trg_write(uid, 'crea8s.fastech.estimate', ids[0], cr) # Tri ?????
        wf_service.trg_validate(uid, 'crea8s.fastech.estimate', ids[0], 'fastech_estimate_sent', cr)
        print "crea8s_fastech: btn_send_email....(using 'trg_write' BOTH)"
        return 1
   
 

class crea8s_fastech_estimate_detail(osv.osv):
    _name = 'crea8s.fastech.estimate.detail'
    _description = 'crea8s_fastech_estimate...'
    _columns = {
        
        'crea8s_fastech_estimate_parent_id': fields.many2one('crea8s.fastech.estimate', 'crea8s.fastech.estimate PARENT id...'),
        'line_no' : fields.integer('LineNo'),
        'product' : fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)]),
        'description': fields.related('product', 'description', type='text', relation='product.product', string='description...', store=True),
#         'description' : fields.char('Description', size=50),
        'qty' : fields.float('Quantity', digits=(3,2)),
        'tax' : fields.float('Tax', digits=(3,2)),
        'unit_price' : fields.float('Unit Price', digits=(3,2)),
        'sub_total' : fields.float('Subtotal', digits=(3,2)),
        'sub_total2' : fields.float('Subtotal2', digits=(3,2)),
        
    }
    

crea8s_fastech_estimate()



